#!/usr/etc/env/ python
# _*_ coding : utf-8 _*_
from flask import Flask
from flask import g
import db
app = Flask(__name__)
app.config.from_object('config')
db.init_db(app)

from apps.index.views import index
app.register_blueprint(index,url_prefix='/')

from apps.user.views import user
app.register_blueprint(user,url_prefix='/user')

from apps.post.views import post 
app.register_blueprint(post,url_prefix='/post')


@app.before_request
def before_request():
    g.db = db.connect_db(app)

@app.teardown_request
def teardown_request(exception):
    db = getattr(g, 'db', None)
    if db is not None:
        db.close()
    g.db.close()
